﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using LongQuanWeb.App_Code;

namespace LongQuanWeb.Admin
{
    public partial class PassWord : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if ((this.Session["username"] == null) || (this.Session["username"].ToString() == string.Empty))
            {
                base.Response.Write("<font color=#ff0000 style='FONT-SIZE: 12px'>对不起,您没足够权限访问此页!!</font><br>");
                base.Response.Write("<a href='Login.aspx' target=_top style='FONT-SIZE: 12px'>重新登陆</a><br>");
                base.Response.End();
            }
            if (!IsPostBack)
            {
                base.Response.Write("<script>parent.window.document.getElementById( 'lbl_title').innerHTML='密码修改'; </script>");
                this.lbl_name.Text = Session["username"].ToString();
            }
        }

        protected void btn_Add_Click(object sender, EventArgs e)
        {
            string old = "select * from [Admins] where Id=1";
            DataTable dt = DbHelperSQL.Query(old).Tables[0];
            if (dt.Rows.Count != 0 && dt != null)
            {
                if (dt.Rows[0]["passwords"].ToString().Trim() != this.txt_old.Text.Trim())
                {
                    base.Response.Write("<script>alert('修改失败，旧密码错误')</script>");
                    return;
                }
            }
            string str = "Update [Admins] set PassWords='" + this.txt_new2.Text + "' where ID=1";
            if (DbHelperSQL.ExecuteSql(str) > 0)
            {
                base.Response.Write("<script>alert('修改成功');window.location='PassWord.aspx'</script>");
            }
            else
            {
                base.Response.Write("<script>alert('修改失败');</script>");
            }
        }

        protected void btn_return_Click(object sender, EventArgs e)
        {
            this.txt_new.Text = "";
            this.txt_new2.Text = "";
            this.txt_old.Text = "";
        }
    }
}